package com.example.administrator.school.bean;

import com.dmcbig.mediapicker.entity.Media;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;

import java.io.File;

/**
 * Created by dmcBig on 2017/7/4.
 */
@Entity
public class MediaBean {
    /**
     * @Entity 　表明这个实体类会在数据库中生成一个与之相对应的表。
     * @Id 　对应数据表中的 Id 字段，有了解数据库的话，是一条数据的唯一标识。
     * @Property(nameInDb = “STUDENTNUM”) 　表名这个属性对应数据表中的 STUDENTNUM 字段。
     * @Property 　可以自定义字段名，注意外键不能使用该属性
     * @NotNull 　该属性值不能为空
     * @Transient 　该属性不会被存入数据库中
     * @Unique 　表名该属性在数据库中只能有唯一值
     */
    @Id(autoincrement = true)
    public Long id;
    public int mediaId;
    public String path;
    public String name;
    public String extension;
    public long createTime;
    public long uploadTime;
    public int mediaType;
    public long size;
    public String parentDir;


    @Generated(hash = 1767040727)
    public MediaBean() {
    }


    @Generated(hash = 1313418803)
    public MediaBean(Long id, int mediaId, String path, String name,
                     String extension, long createTime, long uploadTime, int mediaType,
                     long size, String parentDir) {
        this.id = id;
        this.mediaId = mediaId;
        this.path = path;
        this.name = name;
        this.extension = extension;
        this.createTime = createTime;
        this.uploadTime = uploadTime;
        this.mediaType = mediaType;
        this.size = size;
        this.parentDir = parentDir;
    }


    public static MediaBean toMediaBean(Media media) {
        MediaBean mediaBean = new MediaBean();
        mediaBean.path = media.path;
        mediaBean.name = media.name;
        mediaBean.extension = media.extension;
        mediaBean.createTime = media.time;
        mediaBean.uploadTime = System.currentTimeMillis();
        mediaBean.mediaType = media.mediaType;
        mediaBean.size = media.size;
        mediaBean.mediaId = media.id;
        mediaBean.parentDir = media.parentDir;
        return mediaBean;
    }

    public static MediaBean toMediaBean(String path) {
        File file = new File(path);
        MediaBean mediaBean = new MediaBean();
        mediaBean.path = file.getPath();
        mediaBean.name = file.getName();
//        mediaBean.extension = file.extension;
//        mediaBean.createTime = file.get;
        mediaBean.uploadTime = System.currentTimeMillis();
        mediaBean.mediaType = 2;
//        mediaBean.size = media.size;
//        mediaBean.mediaId = media.id;
//        mediaBean.parentDir = media.parentDir;
        return mediaBean;
    }

    public Media toMedia() {
        Media media = new Media(
                path,
                name,
                createTime,
                mediaType,
                size,
                mediaId,
                parentDir);
        return media;
    }

    public Long getId() {
        return this.id;
    }


    public void setId(Long id) {
        this.id = id;
    }


    public int getMediaId() {
        return this.mediaId;
    }


    public void setMediaId(int mediaId) {
        this.mediaId = mediaId;
    }


    public String getPath() {
        return this.path;
    }


    public void setPath(String path) {
        this.path = path;
    }


    public String getName() {
        return this.name;
    }


    public void setName(String name) {
        this.name = name;
    }


    public String getExtension() {
        return this.extension;
    }


    public void setExtension(String extension) {
        this.extension = extension;
    }


    public long getCreateTime() {
        return this.createTime;
    }


    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }


    public long getUploadTime() {
        return this.uploadTime;
    }


    public void setUploadTime(long uploadTime) {
        this.uploadTime = uploadTime;
    }


    public int getMediaType() {
        return this.mediaType;
    }


    public void setMediaType(int mediaType) {
        this.mediaType = mediaType;
    }


    public long getSize() {
        return this.size;
    }


    public void setSize(long size) {
        this.size = size;
    }


    public String getParentDir() {
        return this.parentDir;
    }


    public void setParentDir(String parentDir) {
        this.parentDir = parentDir;
    }


}
